package com.nbsaas.boot.controller.app;

import com.nbsaas.boot.app.ext.apis.AppExtApi;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.app.api.domain.request.AppRequest;
import com.nbsaas.boot.app.api.domain.request.AppSearch;
import com.nbsaas.boot.app.api.domain.response.AppResponse;
import com.nbsaas.boot.app.api.domain.simple.AppSimple;
import com.nbsaas.boot.app.api.apis.AppApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import jakarta.annotation.Resource;

/**
*  控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/app")
public class AppController {


    @Resource
    private AppApi appApi;

    @Resource
    private AppExtApi appExtApi;

    /**
    * 搜索数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("app:search")
    @PostMapping("/search")
    public PageResponse <AppSimple> search(@RequestBody AppSearch request) {
        return appApi.search(request);
    }

    /**
    * 列表数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("app:list")
    @PostMapping("/list")
    public ListResponse<AppSimple> list(@RequestBody AppSearch request) {
        return appApi.list(request);
    }

    /**
    * 添加数据
    *
    * @param request
    * @return
    */
    @RequiresPermissions("app:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject <AppResponse> create(@RequestBody @Validated(AddOperator.class) AppRequest request) {
        return appExtApi.create(request);
    }

   /**
   * 修改数据
   * @param request
   * @return
   */
   @RequiresPermissions("app:update")
   @UpdateData
   @PostMapping("/update")
   public ResponseObject<AppResponse> update(@RequestBody @Validated(UpdateOperator.class) AppRequest request) {
       return appExtApi.update(request);
   }

    /**
    * 删除数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("app:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AppRequest request) {
        return appApi.delete(request);
    }

    /**
    * 查看数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("app:view")
    @PostMapping("/view")
    public ResponseObject <AppResponse> view(@RequestBody @Validated(ViewOperator.class) AppRequest  request) {
        return appApi.view(request);
    }
}